using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel;
using System.Collections;

namespace ResourceBlender_Express {
    /// <summary>
    /// A translation used by one or more resources
    /// </summary>
    public class RBTranslation : INotifyPropertyChanged {
        private string languageCode = string.Empty,
                       translation = string.Empty,
                       comment = string.Empty;
        /// <summary>
        /// Gets or sets the language code of this translation.
        /// </summary>
        /// <value>The language code.</value>
        public string LanguageCode {
            get { return languageCode; }
            set {
                languageCode = value;
                OnPropertyChanged("LanguageCode");
            }
        }
        /// <summary>
        /// Gets or sets the translated text.
        /// </summary>
        /// <value>The translation.</value>
        public string Translation {
            get { return translation; }
            set {
                translation = value;
                OnPropertyChanged("Translation");
            }
        }
        /// <summary>
        /// Gets or sets the comment.
        /// </summary>
        /// <value>The comment.</value>
        public string Comment {
            get { return comment; }
            set {
                comment = value;
                OnPropertyChanged("Comment");
            }
        }

        /// <summary>
        /// Initializes a new <see cref="RBTranslation"/>.
        /// </summary>
        public RBTranslation() { }

        /// <summary>
        /// Initializes a new <see cref="RBTranslation"/>.
        /// </summary>
        /// <param name="languageCode">The language code.</param>
        /// <param name="translation">The translated text.</param>
        /// <param name="comment">The comment.</param>
        public RBTranslation(string languageCode, string translation, string comment) {
            this.languageCode = languageCode;
            this.translation = translation;
            this.comment = comment;
        }

        /// <summary>
        /// Returns the translated text.
        /// </summary>
        /// <returns>
        /// A <see cref="T:System.String"/> that represents the current <see cref="T:System.Object"/>.
        /// </returns>
        public override string ToString() {
            return Translation;
        }

        public event PropertyChangedEventHandler PropertyChanged;
        protected virtual void OnPropertyChanged(string strPropertyName) {
            if(PropertyChanged != null) {
                PropertyChanged(this, new PropertyChangedEventArgs(strPropertyName));
            }
        }
    }

    /// <summary>
    /// Compares entries in a dictionary by name.
    /// </summary>
    public class ObservableTranslationDictionaryComparer : IComparer<DictionaryEntry> {
        CaseInsensitiveComparer comp = new CaseInsensitiveComparer();
        public int Compare(DictionaryEntry x, DictionaryEntry y) {
            return comp.Compare((x.Value as RBTranslation).Translation, (y.Value as RBTranslation).Translation);
        }
    }
}
